#include "TestClaveSimple.h"

#include "includes.h"
#include "TipoClaveAlumnoDNI.h"
#include "TipoClaveChar.h"
#include "Alumno.h"

TestClaveSimple::TestClaveSimple() {

}

TestClaveSimple::~TestClaveSimple() {

}

void TestClaveSimple::run() {

	this->test();
	this->test2();
}

void TestClaveSimple::setup() {

}

void TestClaveSimple::test() {

	TipoClaveAlumnoDNI extractor;
	Alumno alumno1;
	Alumno alumno2;
	Alumno alumno3;

	alumno1.setDocumento(10001020);
	alumno2.setDocumento(321321);
	alumno3.setDocumento(3211);

	alumno1.setEdad(19);
	alumno2.setEdad(20);
	alumno3.setEdad(61);

	Bytes bytesAlumno1;
	Bytes bytesAlumno2;
	Bytes bytesAlumno3;

	bytesAlumno1 = alumno1.serializarse();
	bytesAlumno2 = alumno2.serializarse();
	bytesAlumno3 = alumno3.serializarse();

	Key claveAl1Extraida = extractor.crearClave(extractor.extraerClave(bytesAlumno1));
	Key claveAl2Extraida = extractor.crearClave(extractor.extraerClave(bytesAlumno2));
	Key claveAl3Extraida = extractor.crearClave(extractor.extraerClave(bytesAlumno3));

	ClaveInt *claveAl1 = new ClaveInt(10001020);
	ClaveInt *claveAl2 = new ClaveInt(321321);
	ClaveInt *claveAl3 = new ClaveInt(3211);

	Key c1(claveAl1);
	Key c2(claveAl2);
	Key c3(claveAl3);

	Key c4 = c3;

	assert(claveAl1Extraida == c1,"Test Clave Alumno 1");
	assert(claveAl2Extraida == c2,"Test Clave Alumno 2");
	assert(claveAl3Extraida == c4,"Test Clave Alumno 3");
}

void TestClaveSimple::test2() {

	TipoClaveChar extractor;

	Bytes dato1("hola");

	Key clave1 = extractor.crearClave(extractor.extraerClave(dato1));

	Key clave2 = clave1;

	assert(clave1 == clave2,"Test Copiar Key string");
}
